package com.biboheart.sc.lexer.tokenizer;

import com.biboheart.sc.lexer.Tokenizer;
import com.biboheart.sc.support.definition.CharType;
import com.biboheart.sc.support.utils.LetterUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 分词器定位
 */
public class TokenizerLocator {
    private static volatile TokenizerLocator sharedInstance;

    public static TokenizerLocator getSharedInstance() {
        TokenizerLocator locator = sharedInstance;
        if (null == locator) {
            synchronized (TokenizerLocator.class) {
                locator = sharedInstance;
                if (locator == null) {
                    locator = new TokenizerLocator();
                    sharedInstance = locator;
                }
            }
        }
        return locator;
    }

    // 定位
    public List<Tokenizer> locate(char ch) {
        CharType charType = LetterUtils.getCharType(ch);
        List<Tokenizer> tokenizerList = new ArrayList<>();
        if (CharType.CHAR_TYPE_NUMBER.equals(charType)) {
            tokenizerList.add(new TokenizerNumber());
        }
        return tokenizerList;
    }
}
